package com.zenghus.v2.statement;

import com.zenghus.v1.Test;

import java.sql.*;

/**
 * @author zenghu
 * @date 2018/4/1317:53
 */
public class StatementHandler {

    public PreparedStatement query(String sql, Object param){
        Connection connection=this.getConnection();
        PreparedStatement preparedStatement = null;
        try{
            preparedStatement = connection.prepareStatement(sql);
            //preparedStatement.setObject(1,param);
        }catch (Exception e){
            e.printStackTrace();
        } finally {

        }
        return preparedStatement;
    }

    public Connection getConnection(){
        Connection connection = null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/gp?useUnicode=true&characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", "root", "123456");
            return connection;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
